<#include "/includes/vars.inc"> 
<@pp.dropOutputFile />
<#assign fileName = "${javaDir}${packageDir}/service/util/SettingsUtil.java">
<#if includeSettings && !pp.outputFileExists(fileName)>
	<@pp.changeOutputFile name="${fileName}" />

package ${project.@rootPackage}.service.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang.Validate;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Settings Utility class
 * <#if project.@author[0]??>@author ${project.@author}</#if>
 */
public class SettingsUtil {

	private static final Logger logger = Logger.getLogger("SettingsUtil");
   
     public static boolean saveSettings(Properties settings, String path) {
        Validate.notNull(path);
        try {
            File settingsFile = new File(path);
            System.out.println("Settings saved at: " + settingsFile.getAbsolutePath() );
            FileOutputStream fout = new FileOutputStream(settingsFile);
            settings.store(fout, "");
            fout.close();
        } catch (IOException ioe) {
            System.out.println("Error while saving settings");
            System.out.println(ioe);
            return false;
        }
        return true;
    }

    public static Properties getSettings(String path) {
        Validate.notNull(path);
        Properties p = new Properties();
        InputStream is = null;
        try {
            File settings = new File(path);
            System.out.println("getSettings from: " + settings.getAbsolutePath());
            if (settings.exists()) {
                is = new FileInputStream(path);
                p.load(is);
                is.close();
            } else {
                System.out.println("Settings file not exist: " + settings.getAbsolutePath());
                p = null;
            }
        } catch (Exception e) {
            System.out.println(e);
            p = null;
        }
        return p;
    }
}
</#if>
